﻿namespace Scheduler
{
    public abstract class Middleware
    {
        protected int St;

        protected object[] UserData;

        protected Middleware(params object[] userData)
        {
            UserData = userData;
        }
        /// <summary>
        /// 过滤
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public abstract bool Filter(Context ctx, EventArgs args);

        public void HandleEvent(Context ctx, EventArgs args)
        {
            if (Filter(ctx, args))
            { 
                DoHandleEvent(ctx, args);
            }
        }

        protected abstract void DoHandleEvent(Context ctx, EventArgs args);
    }
}